const login_js = require('../../utils/login.js')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    count_idx: 0,
    first_bit_idx: 0,
    second_bit_idx: 0,
    model_idx: 0,
    count_list: ['10个问题', '20个问题', '30个问题', '50个问题', '100个问题', ],
    first_bit_list: ['个位数', '两位数', '三位数', '四位数', '五位数'],
    second_bit_list: ['个位数', '两位数', '三位数', '四位数', '五位数'],
    model_list: ['加法', '减法', '乘法', '除法', '混合运算'],
    model_title: '',
    modal_show: false,
    is_dark: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setModelTitle()
    this.setData({
      is_dark: app.global_data.darkness
    })
  },
  onShow() {
    this.setData({
      is_dark: app.global_data.darkness
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  /* 
  朋友圈?
  */
  onShareTimeline() {

  },
  ...login_js.methods,
  /**
   * 登录时候获取用户信息回调
   */
  async getUserInfo(e) {
    await this.getProfile()
    this.clickModalCancel()
  },
  clickModalCancel() {
    this.setData({
      modal_show: false,
    })
  },
  /* 设置问题数 */
  setTestModel(e) {
    let {
      idx,
      model
    } = e.currentTarget.dataset
    switch (model) {
      case 'count':
        this.setData({
          count_idx: +idx,
        })
        break
      case 'first_bit':
        this.setData({
          first_bit_idx: +idx,
        })
        break
      case 'second_bit':
        this.setData({
          second_bit_idx: +idx,
        })
        break
      case 'model':
        this.setData({
          model_idx: +idx,
        })
        break
      default:
        break
    }
    this.setModelTitle()
  },
  /* 设置模式标题 */
  setModelTitle() {
    this.setData({
      model_title: this.data.count_list[this.data.count_idx] + ":" + this.data.first_bit_list[this.data.first_bit_idx] + "和" + this.data.second_bit_list[this.data.second_bit_idx] + "的" + this.data.model_list[this.data.model_idx],
    })
  },
  /* 开始游戏 */
  toGame() {
    // // 登录
    // // 如果未登录则弹框
    // if ( !app.global_data.user_data.openid) {
    //   this.setData({
    //     modal_show: true
    //   })
    //   return
    // }
    let test_model = {
      count_idx: this.data.count_idx,
      first_bit_idx: this.data.first_bit_idx,
      second_bit_idx: this.data.second_bit_idx,
      model_idx: this.data.model_idx,
    }
    let score_model = [this.data.count_idx, this.data.first_bit_idx, this.data.second_bit_idx, this.data.model_idx]
    wx.setStorageSync('test_model', test_model)
    wx.setStorageSync('score_model', score_model)
    wx.navigateTo({
      url: `/pages/game/game?title=${this.data.model_title}`,
    })
  }
})